package it.luigiarpino.sudoku;

import javax.swing.*;
import java.awt.*;


public class GuiSoluzione extends javax.swing.JDialog {
    
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTable tabella;
    private javax.swing.JPanel pannello;
    private Integer[][] soluzione;
    private Sudoku s;
    
    /** Creates a new instance of GUI_Soluzione */
    public GuiSoluzione(java.awt.Frame parent, boolean modal,Sudoku s) {
        super(parent,modal);
        try 
        { 
            javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); 
        } 
        catch(Exception e) {  }
        this.tabella=new JTable();
        this.pannello=new JPanel();
        this.soluzione=new Integer[9][9];
        this.s=s;
        for (int i=0;i<=8;i++){
            for (int j=0;j<=8;j++){
                this.soluzione[i][j]=s.GetElemSol(i+1,j+1);
            }
        }
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        this.setTitle("Sudoku solution");

        String[] titoli=new String[9];
        this.tabella.setModel(new javax.swing.table.DefaultTableModel(soluzione,titoli));
        this.pannello.setLayout(new BorderLayout());
        this.pannello.setBorder(javax.swing.BorderFactory.createEmptyBorder(30,30,30,30));
        
        
        

        
        MyTableModelSudoku tSudoku=new MyTableModelSudoku(this.s);
        this.tabella.setAutoCreateColumnsFromModel(true);
        this.tabella.setModel(tSudoku);
        this.tabella.setPreferredSize(new java.awt.Dimension(270, 270));
        
        this.tabella.setRowHeight(40);
        this.tabella.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0)));
        this.tabella.setFont(new java.awt.Font("SansSerif", 0, 20));
        this.tabella.setDefaultRenderer(String.class,new CellRendererSolution(this.s));
        
        this.pannello.add(this.tabella,BorderLayout.CENTER);
        this.getContentPane().setLayout(new java.awt.BorderLayout());
        this.getContentPane().add(this.pannello,BorderLayout.CENTER);
        this.pack();
        this.setSize(400,450);  
        this.setResizable(false);
        this.setLocation(500, 10);
    }
    
    public static void main(String args[]) {
        new GuiSoluzione(new javax.swing.JFrame(), true ,new Sudoku(2,false)).setVisible(true);
    }
    
}
